<style lang='less'>
  .yangxing {
    background-color: red;
    color: red;
  }
  .demo-drawer-footer{
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    background: #fff;
  }
  .page_style {
    margin: 20px 5px;
  }
  .input-frame {
    width: 120px;
    margin-right: 10px;
  }
  .house-list > .group {
    background: white;
    padding: 10px;
    margin-top: 10px;
  }
  .house-list > .group > .item {
    border-bottom: 1px solid #f5f5f5;
    padding: 10px 0;
  }
  .house-list > .group > .item .top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
  }

  .house-list > .group > .item .title {
    font-size: 14px;
    color: #333333;
  }
  .house-list > .group > .item .address {
    font-size: 12px;
    color: gray;
    display: flex;
    align-items: center;
  }
  .house-list > .group > .item .detail {
    font-size: 12px;
    color: dodgerblue;
  }
  .opt-area-02 {
    display: flex;
    align-items: center;
    flex-direction: column;
    border: 1px solid #abdcff;
    background-color: #f0faff;
    padding: 8px 16px 8px 16px;
    border-radius: 4px;
    margin-bottom: 10px;
  }
  .opt-area-02 .right-con {
    width: 100%;
    margin-top: 5px;
    display: flex;
  }
  .opt-area-02 .left-con {
    font-size: 14px;
    width: 100%;
  }
  .opt-area-02 .left-con span {
    font-weight: bold;
  }
  .opt-area-02 .right-con input {
    width: 164px;
    margin-right: 10px;
  }
  .opt-area-02 .right-con .input-frame {
    width: 200px;
    margin-right: 10px;
  }
  .table-action-btn {
    margin-right: 3px;
  }
  // .container >>> .ivu-btn-small {
  //     height: 24px;
  //     padding: 0 5px;
  //     font-size: 12px;
  //     border-radius: 3px;
  // }
  .btn-action {
    margin-bottom: 10px;
  }
  .page_style .input-vaccines .ivu-select-single .ivu-select-selection {
    height: 50px;
    position: relative;
  }
  .page_style .ivu-select-selection .ivu-select-selected-value {
    display: block;
    height: 30px;
    line-height: 30px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-left: 8px;
    padding-right: 24px;
  }
  //.mp10 {
  //    margin-right: 10px;
  //}
  //.title-style {
  //  color: red;
  //}
  //.mb20 {
  //  margin-bottom: 20px;
  //}
  //.mt20 {
  //  margin-top: 20px;
  //}
  //.ivu-table-row {
  //  height: 57px;
  //}
  //.ivu-form-item-label {
  //  margin-top: 8px;
  //}
  //.demo-spin-icon-load{
  //  animation: ani-demo-spin 1s linear infinite;
  //}
  //@keyframes ani-demo-spin {
  //  from { transform: rotate(0deg);}
  //  50%  { transform: rotate(180deg);}
  //  to   { transform: rotate(360deg);}
  //}
  //.demo-spin-col{
  //  height: 100px;
  //  position: relative;
  //  /*border: 1px solid #eee;*/
  //}
  //.noticeModalDivEx {
  //  height: 200px;
  //  line-height: 200px;
  //  width: 1000px;
  //  color: red;
  //  text-align: center;
  //  font-size: 2rem;
  //}
  //.back-img {
  //  background-image: url('../../../assets/hesuan/hs-back2.png');
  //  background-position: center;
  //}
  //.back-img2 {
  //  background-image: url('../../../assets/hesuan/hs-back1.png');
  //  background-position: center;
  //}
  //.back-img1 {
  //  background-image: url('../../../assets/hesuan/hs-back3.png');
  //  background-position: center;
  //}
  //.tips-menu-v31 .desc {
  //  font-size: 16px;
  //  font-weight: 500;
  //  // margin-bottom: 5px;
  //  // margin-top: 5px;
  //}
</style>
<template>
  <div class="container">
    <div class="opt-area-02">
      <div class="right-con">
        <!-- <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px;margin-right:5px">设置全选</Button>
        <Button type="info" size="small" @click="handleSelectAll(true)" style="margin-top: 5px;margin-right:5px">取消全选</Button>
        <Button type="info" size="small" @click="inspection()" style="margin-top: 5px;margin-right:5px">修改结果</Button> -->
        <div class="input-frame" style="width: 164px">
          <Input v-model="params.vaccines_no" class="div-search" placeholder="请输入疫苗批次号"></Input>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input v-model="params.card_no" class="div-search" placeholder="请输入身份证号"></Input>
        </div>
        <div class="input-frame" style="width: 100px">
          <Select v-model="params.vaccines_needle"  placeholder="针剂">
            <Option value="">全部</Option>
            <Option value="1">一针剂</Option>
            <Option value="2">二针剂</Option>
            <Option value="3">三针剂</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 100px">
          <Select v-model="params.vaccines_num" placeholder="接种次数">
            <Option value="">全部</Option>
            <Option value="1">第一针</Option>
            <Option value="2">第二针</Option>
            <Option value="3">第三针</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px">
          <DatePicker type="date" v-model="params.vaccines_date" placeholder="选择接种日期" style="width: 164px"></DatePicker>
        </div>
        <div class="input-frame"  style="width: 30px;margin-left:90px">
          <Button type="primary" @click="search()" class="search-btn"><Icon type="ios-search" />搜索</Button>
        </div>
      </div>
    </div>
    <Table  :loading="loading" :columns="columns1" ref="selection"  :data="data1"  size="small" border>
      <template slot-scope="{ row }" slot="photo_url">
        <img :src="row.photo_url"  preview="0" preview-text="证件编号" style="width:25px;height:30px">
      </template>
    </Table>
    <!--<vxe-table
      border
      show-overflow
      :loading="loading"
      size="small"
      align="center"
      :data="data1">
      <vxe-table-column type="seq" width="60" title="序号"></vxe-table-column>
      <vxe-table-column field="photo_url" title="头像" width="200">
        <template v-slot="{ row }">
          <img :src="row.photo_url" style="width:25px;height:30px">
        </template>
      </vxe-table-column>
      <vxe-table-column field="name" title="姓名" width="200"></vxe-table-column>
      <vxe-table-column field="card_type" title="证件类型" width="200">
        <template v-slot="{ row }">
          <span v-if="row.card_type==='1'">身份证号</span>
          <span v-if="row.card_type==='2'">军官证</span>
          <span v-if="row.card_type==='3'">护照</span>
          <span v-if="row.card_type==='4'">港澳通行证</span>
          <span v-if="row.card_type==='5'">台胞证</span>
        </template>
      </vxe-table-column>
      <vxe-table-column field="card_no" title="证件号" width="300"></vxe-table-column>
      <vxe-table-column field="mobile" title="电话号码" width="300"></vxe-table-column>
      <vxe-table-column field="address" show-overflow title="地址" width="350"></vxe-table-column>
      <vxe-table-column field="vaccines_no" title="批次号" width="300"></vxe-table-column>
      <vxe-table-column field="vaccines_needles" title="针剂" width="300"></vxe-table-column>
      <vxe-table-column field="vaccines_nums" title="接种次数" width="300"></vxe-table-column>
      <vxe-table-column field="vaccines_time"  title="接种时间" width="300"></vxe-table-column>
      <vxe-table-column field="status" title="留观执行状态" width="300"></vxe-table-column>
      <vxe-table-column title="操作" fixed="right" width="150">
        <template v-slot="{ row }" #default>
          <Button type="success" size="small" style="margin-right: 5px" @click="getVaccinationList(row)">不良反应</Button>
        </template>
      </vxe-table-column>
    </vxe-table>-->
    <Page class="page_style" :total="totalnum" :current="currentPageNo"
          :page-size="currentPageSize" @on-change="changePageNo" show-total  show-sizer @on-page-size-change="sizeL" style="height: 30px;line-height: 30px;font-size: 12px;" />
    <Drawer title="不良反应详情" v-model="model.show" width="720" >
      <Card title="社区反馈">
        <Form>
          <FormItem label="常见不良反应:" label-position="top">
            <RadioGroup v-model="paramData.status" @on-change="updateStatus()">
              <Radio style="margin-top: 1px" label="0" border>无不良反应</Radio>
              <Radio style="margin-top: 5px" label="1" border>出现不良反应</Radio>
            </RadioGroup>
          </FormItem>
        </Form>
        <Form  v-if="status">
          <FormItem label="不良反应时间:" label-position="top">
            <DatePicker type="datetime" v-model="unhealthy_tendencies_time" placeholder="请选择开始时间" style="width: 373px"></DatePicker>
          </FormItem>
          <FormItem label="常见不良反应:" label-position="top">
            <CheckboxGroup v-model="unhealthy_tendencies">
              <Checkbox style="margin-top: 1px" label="0" border>发热</Checkbox>
              <Checkbox style="margin-top: 5px" label="1" border>干咳</Checkbox>
              <Checkbox style="margin-top: 5px" label="2" border>乏力</Checkbox>
              <Checkbox style="margin-top: 5px" label="3" border>咳痰</Checkbox>
              <Checkbox style="margin-top: 5px" label="4" border>咽痛</Checkbox>
              <Checkbox style="margin-top: 5px" label="5" border>腹泻</Checkbox>
              <Checkbox style="margin-top: 5px" label="6" border>味觉异常</Checkbox>
              <Checkbox style="margin-top: 5px" label="7" border>嗅觉异常</Checkbox>
              <Checkbox style="margin-top: 5px" label="8" border>其他</Checkbox>
            </CheckboxGroup>
          </FormItem>
          <FormItem label="其他不良反应:" label-position="top" >
            <Input v-model="formData.unhealthy_tendencies_other" type="textarea" :rows="3" placeholder="请输入其他不良反应" />
          </FormItem>
        </Form>
        <Form>
          <div>
            <Button style="margin-right: 8px" @click="model.show = false">取消</Button>
            <Button type="primary" @click="createAdverseReactions">提交</Button>
          </div>
        </Form>
      </Card>
    </Drawer>
  </div>
</template>

<script>
import { findCommunityVaccinationList, createCommunityAdverseReactions, getCommunityVaccinationList, getDictList } from '@/api/yi-qing-fang-kong'
import { date0str, date2str } from '@/api/eventlist'
export default {
  data () {
    return {
      unhealthy_tendencies_time: '',
      status: false,
      loading: true,
      loading1: true,
      dicList: [
        { label: '身份证号', value: '1' },
        { label: '军官证', value: '2' },
        { label: '护照', value: '3' }
      ],
      formData: {
        unhealthy_tendencies_time: '',
        ym_company_code: ''
      },
      formData2: {},
      formData3: {},
      paramData: {},
      unhealthy_tendencies: [],
      adverse: '',
      model: {
        show: false
      },
      row: '',
      searchInfo: {
        totalnum: 0,
        currentPageNo: 1,
        currentPageSize: 10
      },
      currentPageNo: 1,
      currentPageSize: 10,
      totalnum: 0,
      params: { pageNo: 1, pageSize: 10 },
      data1: [],
      columns1: [
        { type: 'index', width: '60', title: '序号', align: 'center' },
        { title: '头像', width: '100', slot: 'photo_url', align: 'center' },
        { title: '姓名', width: '100', key: 'name', align: 'center' },
        { title: '证件类型', width: '100', key: 'card_name', align: 'center' },
        { title: '身份证号', width: '160', key: 'card_no', align: 'center' },
        { title: '手机号', width: '130', key: 'mobile', align: 'center' },
        { title: '地址', width: '320', key: 'address', align: 'center' },
        { title: '批次号', width: '100', key: 'vaccines_no', align: 'center' },
        { title: '针剂', width: '100', key: 'vaccines_needles', align: 'center' },
        { title: '接种次数', width: '100', key: 'vaccines_nums', align: 'center' },
        { title: '接种时间', width: '150', key: 'vaccines_time', align: 'center' },
        { title: '留观执行状态', width: '100', key: 'status', align: 'center' },
        { title: '操作',
          align: 'center',
          width: '100',
          fixed: 'right',
          key: 'action',
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: {
                  type: 'success',
                  size: 'small'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    this.model.show = true
                    this.row = params.row
                    this.getVaccinationList(params.row)
                  }
                }
              }, '不良反应')
            )
            return h('div', temp)
          }
        }
      ]
    }
  },
  methods: {
    updateStatus () {
      if (this.paramData.status === '0') {
        this.status = false
        this.formData = {}
      } else if (this.paramData.status === '1') {
        this.status = true
      }
    },
    init (param) {
      // let that = this
      param.vaccines_date = date2str(param.vaccines_date)
      findCommunityVaccinationList(param).then(res => {
        if (res.data.errcode === 0) {
          this.data1 = res.data.data.results
          this.data1.forEach(function (temp) {
            if (temp.vaccines_needle === '1') {
              temp.vaccines_needles = '一针剂'
            }
            if (temp.vaccines_needle === '2') {
              temp.vaccines_needles = '二针剂'
            }
            if (temp.vaccines_needle === '3') {
              temp.vaccines_needles = '三针剂'
            }
            if (temp.vaccines_num === '1') {
              temp.vaccines_nums = '第一针'
            }
            if (temp.vaccines_num === '2') {
              temp.vaccines_nums = '第二针'
            }
            if (temp.vaccines_num === '3') {
              temp.vaccines_nums = '第三针'
            }
            if (temp.status === undefined || temp.status === '') {
              temp.status = '否'
            } else {
              temp.status = '是'
            }
            // that.dicList.forEach(function (tmp) {
            //   if (temp.card_type === tmp.value) {
            //     temp.card_typename = tmp.label
            //   }
            // })
          })
          this.totalnum = res.data.data.totalRecord
          console.log(this.data1, '样瓶列表')
          this.loading = false
        } else {
          this.$Notice.error({
            title: '获取样瓶列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getVaccinationList (params) {
      this.model.show = true
      this.row = params
      getCommunityVaccinationList(params).then(res => {
        if (res.data.errcode === 0) {
          this.formData = res.data.data.pc
          this.formData2 = res.data.data.sst
          this.formData3 = res.data.data.sq
          this.paramData.status = this.formData.status
          this.unhealthy_tendencies_time = this.formData.unhealthy_tendencies_time
          this.updateStatus()
          // if (this.formData.unhealthy_tendencies) {
          this.unhealthy_tendencies = this.formData.unhealthy_tendencies.split(',')
          // }
        } else {
          this.$Notice.error({
            title: '获取不良反应失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    createAdverseReactions () {
      this.formData.pid = this.row.id
      this.formData.source = '0'
      this.formData.status = this.paramData.status
      this.formData.ym_company_code = this.row.ym_company_code
      if (this.unhealthy_tendencies.length > 0) {
        this.formData.unhealthy_tendencies = this.unhealthy_tendencies.join(',')
      }
      if (this.unhealthy_tendencies_time) {
        this.formData.unhealthy_tendencies_time = date0str(this.unhealthy_tendencies_time)
      }
      createCommunityAdverseReactions(this.formData).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({
            title: '保存成功',
            desc: 'success'
          })
          this.model.show = false
        } else {
          this.$Notice.error({
            title: '保存失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    search () {
      this.params.pageNo = 1
      this.init(this.params)
    },
    changePageNo (pageNo) {
      console.log(pageNo, '页数')
      this.currentPageNo = pageNo
      this.params.pageNo = pageNo
      this.init(this.params)
    },
    sizeL (pageSize) {
      this.searchInfo.currentPageSize = pageSize
      this.changePageNo()
    },
    // 获取字典数据
    getDicInfo () {
      getDictList({ 'type': 'csc_squser_cardtype' }).then(ret => {
        if (ret.data.errcode === 0) {
          this.dicList = ret.data.data.results
          console.log(this.dicList, '字典')
        } else {
          this.$Notice.error({ title: '获取字典列表失败', desc: '' })
        }
      })
    }
  },
  mounted () {
    this.getDicInfo()
    this.init(this.params)
  }
}
</script>
<style>
  .div-search{
    width: 200px;
  }
  .form-header{
    height: 40px;
  }
  .search-btn{
    margin-left: -55px;
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .ios-search{
    text-align: left;
  }
</style>
